/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 2 -*- */
/**
* @file TestShm.c
* 
* Function for testing the shm library code.
* 
* @author Miguel Ángel Vílchez López 2009 <sacra@openmatica.es>
*
* Codigo is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* Codigo is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along
* with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <shm.cpp>

/**
* @example TestShm.c
*/

int main(int argc, char *argv[])
{
	if(argc<2)
	{
		puts("\nUSE:\nTestShm <type>\n");
		puts("types:");
		puts("\tread <id>");
		puts("\twrite <id> <cadena>\n");
		puts("\t  e.g.");
		puts("\t    TestShm read 13 => Reads from the id '13' shared memory segment.");
		puts("\t    TestShm write 13 \"Hello world\" => Sends 'Hello world' to the id '13' shared memory segment.\n");

		exit(EXIT_SUCCESS);
	}

	if(strcmp(argv[1],"read")==0)
	{
		CMShm here(atoi(argv[2]),1024);
		char *buffer;
		buffer = (char *)malloc(sizeof(char) * 1024);
		here.read(buffer);
		printf("%s\n",buffer);
		free(buffer);
	}

	if(strcmp(argv[1],"write")==0)
	{
		CMShm here(atoi(argv[2]),1024);
		here.write(argv[3]);
	}

}
